<?php
class Default_Form_RegisterForm extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');

        $user = new Default_Model_User();

        $definition = $user->getTable()->getColumnDefinition('first_name');
        $this->addElement('text', 'first_name', array(
            'label'      => 'First name',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength',
                      'options' => array(0, $definition['length']))
            )
        ));

        $definition = $user->getTable()->getColumnDefinition('last_name');
        $this->addElement('text', 'last_name', array(
            'label'      => 'Last name',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength',
                      'options' => array(0, $definition['length']))
            )
        ));

        $definition = $user->getTable()->getColumnDefinition('email');
        $this->addElement('text', 'email', array(
            'label'      => 'Email',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'EmailAddress',
                new Areal_Validate_UniqueUserEmail(),
                array('validator' => 'StringLength',
                      'options' => array(0, $definition['length']))
            )
        ));

        $definition = $user->getTable()->getColumnDefinition('password');
        $this->addElement('password', 'password', array(
            'label'      => 'Enter your password',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength',
                      'options' => array(0, $definition['length'])),
                new Areal_Validate_PasswordConfirmation(),
            )
        ));

        $this->addElement('password', 'password_2', array(
            'label'      => 'Repeat your password',
            'required'   => false,
            'filters'    => array('StringTrim'),
        ));

        $this->addElement('captcha', 'captcha', array(
            'label'      => 'Please enter the 5 letters displayed below:',
            'required'   => true,
            'captcha'    => array('captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300, 'font' => DATA_PATH . 'fonts/big.flf')
        ));

        $this->addElement('submit', 'submit', array(
            'label'    => 'Register',
        ));
    }
}

